READ Statement ---------------------------------------------------------------------------- Action Reads values from a DATA statement and assigns the values to variables. Syntax READ variablelist Remarks The argument variablelist is a series of BASIC variables that receive the data from a DATA statement. The variables are separated by commas and can be string or numeric. Only individual elements of a record variable can appear in a READ statement. The following table describes what happens when you try to read data of one data type into a variable with a different data type. ----------------------------------------------------------------------------- If you try to read Into this. The result is. If you try to read Into this. The result is. this. ---------------------------------------------------------------------------- String value Numeric variable A run-time error. Numeric value String variable The value is stored as a string of numerals (no error is produced). Any numeric value Integer variables The value is rounded before it is assigned to the variable. Numeric value A variable not large A run-time error. enough to handle the numeric variable. String value Fixed-length string Truncated if the string variables is too long; left-justified and padded with blanks if If you try to read Into this. The result is. this. padded with blanks if the string is shorter than the variable. Each variable in a READ statement receives its value from some DATA statement. Which value the variable receives depends on how many values have previously been read. The values of all DATA statements in a module can be considered as a single list of values. Each value in this list is assigned in turn to the variables specified in READ statements. It doesn't matter how many values are specified in a given DATA statement or how many variables are specified in a READ statement. If you attempt to read more values than are specified in all of the statements combined, BASIC generates the error message Out of data. Use the RESTORE statement to reread DATA statements. See Also DATA, RESTORE Example The following example shows how you can use a READ statement to assign values to the user-defined type Employee. TYPE Employee EmpName AS STRING * 35 SocSec AS STRING * 11 JobClass AS INTEGER END TYPE CLS ' Clear screen. DIM ThisEmp AS Employee DATA "Julia Magruder","300-32-3403",3 DATA "Amelie Reeves Troubetzkoy","777-29-3206",7 ' Read first data input line and verify by printing data. READ ThisEmp.EmpName, ThisEmp.SocSec, ThisEmp.JobClass PRINT "Employee is "; ThisEmp.EmpName PRINT "Employee's social security number is "; ThisEmp.SocSec PRINT "Employee's job class is"; ThisEmp.JobClass PRINT' Print blank line ' Read second data input line and verify. READ ThisEmp.EmpName, ThisEmp.SocSec, ThisEmp.JobClass PRINT "Employee is "; ThisEmp.EmpName PRINT "Employee's social security number is "; ThisEmp.SocSec PRINT "Employee's job class is"; ThisEmp.JobClass Output Employee is Julia Magruder Employee's social security number is 300-32-3403 Employee's job class is 3 Employee is Amelie Reeves Troubetzkoy Employee's social security number is 777-29-3206 Employee's job class is 7